package com.gitee.zhziyun.meowchat.meowserver.dao;

import com.gitee.zhziyun.meowchat.meowserver.entity.User;
import com.gitee.zhziyun.meowchat.meowserver.mapper.UserMapper;
import com.gitee.zhziyun.meowchat.meowserver.utils.DBUtil;

import java.util.List;

public class UserDaoImpl implements UserDao {

    @Override
    public User findByName(String username) {
        String sql = "select * from meow_users where username = ?";
        return DBUtil.querySingle(sql, new UserMapper(), username);
    }

    @Override
    public List<User> findAll() {
        return DBUtil.executeQuery("select * from meow_users", new UserMapper());
    }

    @Override
    public boolean add(String username, String password) throws Exception {
        String sql = "insert or ignore into meow_users(username, password) values(?,?)";
        return DBUtil.executeUpdate(sql, username, password) != 0;
    }
}
